//
//  WFPresentationController.swift
//  WeiBoSwift
//
//  Created by admin on 2017/12/12.
//  Copyright © 2017年 admin. All rights reserved.
//

import UIKit

let kScreenHeight = UIScreen.main.bounds.size.height
let kScreenWidth = UIScreen.main.bounds.size.width

class WFPresentationController: UIPresentationController {
    
    lazy private var coverView : UIView = UIView()
    var presentFrame : CGRect = CGRect.zero
    
    override func containerViewWillLayoutSubviews() {
        presentedView?.frame = presentFrame
    // CGRect.init(x: (kScreenWidth - 150) / 2, y: 50, width: 150, height: 200)
        
        // 添加蒙版
        setupCoverView();
    }
    
    func setupCoverView() {
        containerView?.insertSubview(coverView, at: 0)
        
        coverView.frame = containerView!.bounds
        coverView.backgroundColor = UIColor.init(white: 0.0, alpha: 0.2)
        
        // 添加手势
        let tapGR : UITapGestureRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(tapGRClick))
        coverView.addGestureRecognizer(tapGR)
    }
    
    @objc private func tapGRClick() {
        presentedViewController.dismiss(animated: true, completion: nil)
    }
    
}
